package com.briup.sms.web.handler;

import com.briup.sms.utils.Result;
import com.briup.sms.utils.ResultCode;
import com.briup.sms.utils.SMSException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author :xuyang
 * @DateTime:2024/1/10 15:35
 * @Version :v1.0.0
 * ClassName:GlobalExceptionHandler
 * Package  :com.briup.sms.web.handler
 * Description:TODO
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e) {
        if (e instanceof SMSException) {
            SMSException es = (SMSException) e;
            return Result.error(es.getResultCode());
        } else {
            e.printStackTrace();
            return Result.error(ResultCode.SYSTEM_INNER_ERROR);
        }
    }
}
